package cn.ekuma.data.ui.android.editor;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import android.content.Context;
import android.util.AttributeSet;

import cn.ekuma.data.dao.I_ParentNode;
import cn.ekuma.data.dao.bean.IKeyed;

public abstract class AbstractParentDAOJEditor <T extends IKeyed,K> extends AbstractDAOJEditor<T> implements I_ParentNode<K>{

    public AbstractParentDAOJEditor(DirtyManager dirty, Context context,
			AttributeSet attrs) {
		super(dirty, context, attrs);
	}

	 protected List<ParentNodeChangeListener<K>> listeners = new ArrayList();

     public final void addObjectChangeListener(ParentNodeChangeListener<K> l) {
        listeners.add(l);
    }

    public final void removeListDataListener(ParentNodeChangeListener<K> l) {
        listeners.remove(l);
    }

    @Override
    public void writeValueInsert(Properties prop) {
        super.writeValueInsert(prop);
        for(ParentNodeChangeListener l:listeners)
            l.parentNodeValueChange(state, this);
    }

    public void writeValueDelete(T value) {
       super.writeValueDelete(value);
       for(ParentNodeChangeListener l:listeners)
            l.parentNodeValueChange(state, this);
    }

    public void writeValueEOF() {
       super.writeValueEOF();
       for(ParentNodeChangeListener l:listeners)
            l.parentNodeValueChange(state, this);
    }

    public void writeValueEdit(T value) {
       super.writeValueEdit(value);
       for(ParentNodeChangeListener l:listeners)
            l.parentNodeValueChange(state, this);
    }


    public IKeyed<K> getParentKey() {
        return obj;
    }

    public Class getParentClass() {
        return getEditClass();
    }

}
